# -*- coding: utf8 -*-

from bottle import run, route, abort, redirect, static_file
from bottle import get, post, request, response
from bottle import debug, default_app
from bottle import Jinja2Template
from session import BlogSessionMiddleware

debug(True)

import blog_views
import xmlrpc_views
import admin.views

def datetimeformat(dt, format):
	return dt.strftime(format)

def show_comment_count(n):
	if not n:
		return u'暂无评论'
	else:
		return u'评论(%s)' % n

def filter_title(text):
	return text.title() if text else ''

Jinja2Template.settings['filters'] = {
	'datetimeformat': datetimeformat,
	'show_comment_count': show_comment_count,
	'title': filter_title
}

@route("/static/:path#.+#")
def staticfiles(path):
	return static_file(path, root="./static")

@route("/pic/:path#.+#")
def staticfiles_blog_pic(path):
	return static_file(path, root="./static/media")

@route("/favicon.ico")
def get_favicon():
	return static_file("favicon.ico", root="./static")

def run_testserver():
	app = BlogSessionMiddleware(default_app())
	run(app=app, host='0.0.0.0', port=8081, reloader=True)
	
if __name__ == '__main__':
	run_testserver()

